package com.lagou.analysis.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zxj
 * 日期类
 */
public class DateUtil {

    public final static String DATE_FORMAT = "yyyy-MM-dd";

    public final static String DATE_FORMAT_HIS = "yyyy/MM/dd";

    public final static String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public final static String DATE_TIME_FORMAT_HIS = "yyyy/MM/dd HH:mm:ss";

    public final static String TIME_HOUR_MIN_FORMAT = "HH:mm";

    public static String getDate(long unixtime, String format) {
        String date = new SimpleDateFormat(format).format(new Date(
                unixtime * 1000L));
        return date;
    }

    public static Date parseToDate(String str, String format) {
        Date date = null;
        try {
             date = new SimpleDateFormat(format).parse(str);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }

    public static long getUnixtime(String date, String format) {
        long unixtime = 0L;
        try {
            unixtime = new SimpleDateFormat(format).parse(date).getTime() / 1000L;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return unixtime;
    }


    public static long getCurrentUnixtime() {
        long unixtime = System.currentTimeMillis() / 1000L;
        return unixtime;
    }



}
